package org.makcro.sms.services.chat.base.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;

import org.makcro.sms.services.chat.model.Agent;
import org.makcro.sms.services.chat.model.AgentGroup;
import org.makcro.sms.services.chat.model.Group;

public class AgentGroupDAO extends AbstractDAO<AgentGroup> implements AgendGroupDao {

	@PersistenceContext
	private EntityManager em;

	public AgentGroupDAO() {
		super(AgentGroup.class);
	}

	public AgentGroup findByAgentAndGroup(Agent agent, Group group) {
		AgentGroup ag = null;
		try {
			ag = (AgentGroup) em.createNamedQuery("AgentGroup.findByAgentAndGroup").setParameter("agent", agent).setParameter("group", group).getSingleResult();
		} catch (NoResultException e) {

		}

		return ag;
	}

	@SuppressWarnings("unchecked")
	public List<AgentGroup> findByAgent(Agent agent) {
		List<AgentGroup> agentGroup = null;
		try {
			agentGroup = (List<AgentGroup>) em.createNamedQuery("AgentGroup.findByAgent").setParameter("agent", agent).getResultList();
		} catch (NoResultException e) {
		}

		return agentGroup;
	}
}